# Maintainer: Daniel Bermond <dbermond@archlinux.org>

pkgname=libilbc
pkgver=3.0.4
pkgrel=2
pkgdesc='A friendly copy of the iLBC codec from the WebRTC project'
arch=('loong64' 'x86_64')
url='https://github.com/TimothyGu/libilbc/'
license=('BSD')
depends=('gcc-libs')
makedepends=('git' 'cmake')
source=("git+https://github.com/TimothyGu/libilbc.git#tag=v${pkgver}?signed"
        'git+https://github.com/abseil/abseil-cpp.git')
validpgpkeys=('9456AFC0814A8139E99483517FE6B095B582B0D4') # Timothy Gu
sha256sums=('SKIP'
            'SKIP')

prepare() {
    git -C libilbc submodule init
    git -C libilbc config --local submodule.abseil.url "${srcdir}/abseil-cpp"
    git -C libilbc submodule update
}

build() {
    cmake -B build -S libilbc \
        -DCMAKE_BUILD_TYPE:STRING='None' \
        -DCMAKE_INSTALL_PREFIX:PATH='/usr' \
        -Wno-dev
    make -C build
}

check() {
    build/ilbc_test 20 libilbc/sample.pcm build/sample-encoded.ilbc build/sample-decoded.pcm
}

package() {
    make -C build DESTDIR="$pkgdir" install
    install -D -m644 libilbc/COPYING "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
    install -D -m644 libilbc/PATENTS -t "${pkgdir}/usr/share/licenses/${pkgname}"
}
